package cn.didi.feidi.androidorder.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import cn.didi.feidi.androidorder.OrderApplication;
import cn.didi.feidi.androidorder.R;


/**
 * 每个需要bar的activity最好都继承这个类
 * Created by king on 2017/7/5.
 */

public abstract class SingleFragmentActivity extends FeidiBaseActivity {
    private TextView networkTip;

    abstract protected Fragment createFragment(Bundle bundle);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.activity_layout_single_fragment);
        FragmentManager fm = getSupportFragmentManager();
        Fragment mFragment = fm.findFragmentById(R.id.container);
        if (mFragment == null) {
            mFragment = createFragment(savedInstanceState);
            fm.beginTransaction().add(R.id.container, mFragment).commit();
        }
        networkTip = (TextView) findViewById(R.id.network_tip);
    }

    @Override
    public void setNetworkTip() {
        super.setNetworkTip();
        if (OrderApplication.networkTip.isShow()) {
            networkTip.setText(OrderApplication.networkTip.getTip());
            networkTip.setOnClickListener(OrderApplication.networkTip
                    .getClickListener());
            networkTip.setVisibility(View.VISIBLE);
        } else {
            networkTip.setText(OrderApplication.networkTip.getTip());
            networkTip.setVisibility(View.GONE);
        }
    }

    @Override
    protected int setFeidiActionBarId() {
        return R.id.action_bar_feidi;
    }
}
